﻿using System;
using System.IO;
using System.Text;

namespace ImgURLUploader
{
    public class SerializeClassHelper
    {
        public static void SerializeObject( string path, object obj)
        {
            try
            {
                string output = Newtonsoft.Json.JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.Indented);
                File.WriteAllText(path, output, Encoding.UTF8);
            }
            catch(Exception ex) { Console.WriteLine("序列化数据失败："+ex.Message); }
        }

        public static object DeserializeObject(string path)
        {
            try
            {
                string readText = File.ReadAllText(path, Encoding.UTF8);
                return Newtonsoft.Json.JsonConvert.DeserializeObject<ConfigModel>(readText);
            }
            catch (Exception ex) { Console.WriteLine("读取序列化数据失败：" + ex.Message); }
            return null;
        }
    }

    public class ConfigModel
    {
        public string BaseImgURL { get; set; } = "http://pic.maxdoc.top";
        public string VerifyURL { get; set; } = "/user/verify";
        public string UploadURL { get; set; } = "/upload/localhost";
        public string UserName { get; set; } = "admin";
        public string Password { get; set; } = "123456";
        public string DealURL { get; set; } = "/deal/identify/";
    }
}
